home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Actual 85 Febrero 2004.iso / Experto / Apache / apache_2.0.48-win32-x86-no_ssl.msi / Data.Cab / F251743_apr_file_io.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-08-23  |  32.8 KB  |  790 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef APR_FILE_IO_H
  56. #define APR_FILE_IO_H
  57.  
  58. /**
  59.  * @file apr_file_io.h
  60.  * @brief APR File I/O Handling
  61.  */
  62.  
  63. #include "apr.h"
  64. #include "apr_pools.h"
  65. #include "apr_time.h"
  66. #include "apr_errno.h"
  67. #include "apr_file_info.h"
  68. #include "apr_inherit.h"
  69.  
  70. #define APR_WANT_STDIO          /**< for SEEK_* */
  71. #define APR_WANT_IOVEC          /**< for apr_file_writev */
  72. #include "apr_want.h"
  73.  
  74. #ifdef __cplusplus
  75. extern "C" {
  76. #endif /* __cplusplus */
  77.  
  78. /**
  79.  * @defgroup apr_file_io File I/O Handling Functions
  80.  * @ingroup APR 
  81.  * @{
  82.  */
  83.  
  84. /**
  85.  * @defgroup apr_file_open_flags File Open Flags/Routines
  86.  * @{
  87.  */
  88.  
  89. /* Note to implementors: Values in the range 0x00100000--0x80000000
  90.    are reserved for platform-specific values. */
  91.  
  92. #define APR_READ       0x00001     /**< Open the file for reading */
  93. #define APR_WRITE      0x00002     /**< Open the file for writing */
  94. #define APR_CREATE     0x00004     /**< Create the file if not there */
  95. #define APR_APPEND     0x00008     /**< Append to the end of the file */
  96. #define APR_TRUNCATE   0x00010     /**< Open the file and truncate to 0 length */
  97. #define APR_BINARY     0x00020     /**< Open the file in binary mode */
  98. #define APR_EXCL       0x00040     /**< Open should fail if APR_CREATE and file
  99.                                         exists. */
  100. #define APR_BUFFERED   0x00080     /**< Open the file for buffered I/O */
  101. #define APR_DELONCLOSE 0x00100     /**< Delete the file after close */
  102. #define APR_XTHREAD    0x00200     /**< Platform dependent tag to open the file
  103.                                         for use across multiple threads */
  104. #define APR_SHARELOCK  0x00400     /**< Platform dependent support for higher
  105.                                         level locked read/write access to support
  106.                                         writes across process/machines */
  107. #define APR_FILE_NOCLEANUP 0x00800 /**< Do not register a cleanup when the file
  108.                                         is opened */
  109. #define APR_SENDFILE_ENABLED 0x01000 /**< Advisory flag that this file should
  110.                                           support apr_sendfile operation */
  111. /** @} */
  112.  
  113. /**
  114.  * @defgroup apr_file_seek_flags File Seek Flags
  115.  * @{
  116.  */
  117.  
  118. /* flags for apr_file_seek */
  119. /** Set the file position */
  120. #define APR_SET SEEK_SET
  121. /** Current */
  122. #define APR_CUR SEEK_CUR
  123. /** Go to end of file */
  124. #define APR_END SEEK_END
  125. /** @} */
  126.  
  127. /**
  128.  * @defgroup apr_file_attrs_set_flags File Attribute Flags
  129.  * @{
  130.  */
  131.  
  132. /* flags for apr_file_attrs_set */
  133. #define APR_FILE_ATTR_READONLY   0x01          /**< File is read-only */
  134. #define APR_FILE_ATTR_EXECUTABLE 0x02          /**< File is executable */
  135. #define APR_FILE_ATTR_HIDDEN     0x04          /**< File is hidden */
  136. /** @} */
  137.  
  138. /** File attributes */
  139. typedef apr_uint32_t apr_fileattrs_t;
  140.  
  141. /** should be same as whence type in lseek, POSIX defines this as int */
  142. typedef int       apr_seek_where_t;
  143.  
  144. /**
  145.  * Structure for referencing files.
  146.  */
  147. typedef struct apr_file_t         apr_file_t;
  148.  
  149. /* File lock types/flags */
  150. /**
  151.  * @defgroup apr_file_lock_types File Lock Types
  152.  * @{
  153.  */
  154.  
  155. #define APR_FLOCK_SHARED        1       /**< Shared lock. More than one process
  156.                                            or thread can hold a shared lock
  157.                                            at any given time. Essentially,
  158.                                            this is a "read lock", preventing
  159.                                            writers from establishing an
  160.                                            exclusive lock. */
  161. #define APR_FLOCK_EXCLUSIVE     2       /**< Exclusive lock. Only one process
  162.                                            may hold an exclusive lock at any
  163.                                            given time. This is analogous to
  164.                                            a "write lock". */
  165.  
  166. #define APR_FLOCK_TYPEMASK      0x000F  /**< mask to extract lock type */
  167. #define APR_FLOCK_NONBLOCK      0x0010  /**< do not block while acquiring the
  168.                                            file lock */
  169. /** @} */
  170.  
  171. /**
  172.  * Open the specified file.
  173.  * @param new_file The opened file descriptor.
  174.  * @param fname The full path to the file (using / on all systems)
  175.  * @param flag Or'ed value of:
  176.  * <PRE>
  177.  *         APR_READ              open for reading
  178.  *         APR_WRITE             open for writing
  179.  *         APR_CREATE            create the file if not there
  180.  *         APR_APPEND            file ptr is set to end prior to all writes
  181.  *         APR_TRUNCATE          set length to zero if file exists
  182.  *         APR_BINARY            not a text file (This flag is ignored on 
  183.  *                               UNIX because it has no meaning)
  184.  *         APR_BUFFERED          buffer the data.  Default is non-buffered
  185.  *         APR_EXCL              return error if APR_CREATE and file exists
  186.  *         APR_DELONCLOSE        delete the file after closing.
  187.  *         APR_XTHREAD           Platform dependent tag to open the file
  188.  *                               for use across multiple threads
  189.  *         APR_SHARELOCK         Platform dependent support for higher
  190.  *                               level locked read/write access to support
  191.  *                               writes across process/machines
  192.  *         APR_FILE_NOCLEANUP    Do not register a cleanup with the pool 
  193.  *                               passed in on the <EM>cont</EM> argument (see below).
  194.  *                               The apr_os_file_t handle in apr_file_t will not
  195.  *                               be closed when the pool is destroyed.
  196.  *         APR_SENDFILE_ENABLED  Open with appropriate platform semantics
  197.  *                               for sendfile operations.  Advisory only,
  198.  *                               apr_sendfile does not check this flag.
  199.  * </PRE>
  200.  * @param perm Access permissions for file.
  201.  * @param cont The pool to use.
  202.  * @remark If perm is APR_OS_DEFAULT and the file is being created, appropriate 
  203.  *      default permissions will be used.  *arg1 must point to a valid file_t, 
  204.  *      or NULL (in which case it will be allocated)
  205.  */
  206. APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new_file, const char *fname,
  207.                                    apr_int32_t flag, apr_fileperms_t perm,
  208.                                    apr_pool_t *cont);
  209.  
  210. /**
  211.  * Close the specified file.
  212.  * @param file The file descriptor to close.
  213.  */
  214. APR_DECLARE(apr_status_t) apr_file_close(apr_file_t *file);
  215.  
  216. /**
  217.  * delete the specified file.
  218.  * @param path The full path to the file (using / on all systems)
  219.  * @param cont The pool to use.
  220.  * @remark If the file is open, it won't be removed until all instances are closed.
  221.  */
  222. APR_DECLARE(apr_status_t) apr_file_remove(const char *path, apr_pool_t *cont);
  223.  
  224. /**
  225.  * rename the specified file.
  226.  * @param from_path The full path to the original file (using / on all systems)
  227.  * @param to_path The full path to the new file (using / on all systems)
  228.  * @param pool The pool to use.
  229.  * @warning If a file exists at the new location, then it will be overwritten.  
  230.  *      Moving files or directories across devices may not be possible.
  231.  */
  232. APR_DECLARE(apr_status_t) apr_file_rename(const char *from_path, 
  233.                                           const char *to_path,
  234.                                           apr_pool_t *pool);
  235.  
  236. /**
  237.  * copy the specified file to another file.
  238.  * @param from_path The full path to the original file (using / on all systems)
  239.  * @param to_path The full path to the new file (using / on all systems)
  240.  * @param perms Access permissions for the new file if it is created.
  241.  *     In place of the usual or'd combination of file permissions, the
  242.  *     value APR_FILE_SOURCE_PERMS may be given, in which case the source
  243.  *     file's permissions are copied.
  244.  * @param pool The pool to use.
  245.  * @remark The new file does not need to exist, it will be created if required.
  246.  * @warning If the new file already exists, its contents will be overwritten.
  247.  */
  248. APR_DECLARE(apr_status_t) apr_file_copy(const char *from_path, 
  249.                                         const char *to_path,
  250.                                         apr_fileperms_t perms,
  251.                                         apr_pool_t *pool);
  252.  
  253. /**
  254.  * append the specified file to another file.
  255.  * @param from_path The full path to the source file (using / on all systems)
  256.  * @param to_path The full path to the destination file (using / on all systems)
  257.  * @param perms Access permissions for the destination file if it is created.
  258.  *     In place of the usual or'd combination of file permissions, the
  259.  *     value APR_FILE_SOURCE_PERMS may be given, in which case the source
  260.  *     file's permissions are copied.
  261.  * @param pool The pool to use.
  262.  * @remark The new file does not need to exist, it will be created if required.
  263.  */
  264. APR_DECLARE(apr_status_t) apr_file_append(const char *from_path, 
  265.                                           const char *to_path,
  266.                                           apr_fileperms_t perms,
  267.                                           apr_pool_t *pool);
  268.  
  269. /**
  270.  * Are we at the end of the file
  271.  * @param fptr The apr file we are testing.
  272.  * @remark Returns APR_EOF if we are at the end of file, APR_SUCCESS otherwise.
  273.  */
  274. APR_DECLARE(apr_status_t) apr_file_eof(apr_file_t *fptr);
  275.  
  276. /**
  277.  * open standard error as an apr file pointer.
  278.  * @param thefile The apr file to use as stderr.
  279.  * @param cont The pool to allocate the file out of.
  280.  * 
  281.  * @remark The only reason that the apr_file_open_std* functions exist
  282.  * is that you may not always have a stderr/out/in on Windows.  This
  283.  * is generally a problem with newer versions of Windows and services.
  284.  * 
  285.  * The other problem is that the C library functions generally work
  286.  * differently on Windows and Unix.  So, by using apr_file_open_std*
  287.  * functions, you can get a handle to an APR struct that works with
  288.  * the APR functions which are supposed to work identically on all
  289.  * platforms.
  290.  */
  291. APR_DECLARE(apr_status_t) apr_file_open_stderr(apr_file_t **thefile,
  292.                                           apr_pool_t *cont);
  293.  
  294. /**
  295.  * open standard output as an apr file pointer.
  296.  * @param thefile The apr file to use as stdout.
  297.  * @param cont The pool to allocate the file out of.
  298.  * 
  299.  * @remark The only reason that the apr_file_open_std* functions exist
  300.  * is that you may not always have a stderr/out/in on Windows.  This
  301.  * is generally a problem with newer versions of Windows and services.
  302.  * 
  303.  * The other problem is that the C library functions generally work
  304.  * differently on Windows and Unix.  So, by using apr_file_open_std*
  305.  * functions, you can get a handle to an APR struct that works with
  306.  * the APR functions which are supposed to work identically on all
  307.  * platforms.
  308.  */
  309. APR_DECLARE(apr_status_t) apr_file_open_stdout(apr_file_t **thefile,
  310.                                           apr_pool_t *cont);
  311.  
  312. /**
  313.  * open standard input as an apr file pointer.
  314.  * @param thefile The apr file to use as stdin.
  315.  * @param cont The pool to allocate the file out of.
  316.  * 
  317.  * @remark The only reason that the apr_file_open_std* functions exist
  318.  * is that you may not always have a stderr/out/in on Windows.  This
  319.  * is generally a problem with newer versions of Windows and services.
  320.  * 
  321.  * The other problem is that the C library functions generally work
  322.  * differently on Windows and Unix.  So, by using apr_file_open_std*
  323.  * functions, you can get a handle to an APR struct that works with
  324.  * the APR functions which are supposed to work identically on all
  325.  * platforms.
  326.  */
  327. APR_DECLARE(apr_status_t) apr_file_open_stdin(apr_file_t **thefile,
  328.                                               apr_pool_t *cont);
  329.  
  330. /**
  331.  * Read data from the specified file.
  332.  * @param thefile The file descriptor to read from.
  333.  * @param buf The buffer to store the data to.
  334.  * @param nbytes On entry, the number of bytes to read; on exit, the number of bytes read.
  335.  * @remark apr_file_read will read up to the specified number of bytes, but 
  336.  *         never more.  If there isn't enough data to fill that number of 
  337.  *         bytes, all of the available data is read.  The third argument is 
  338.  *         modified to reflect the number of bytes read.  If a char was put 
  339.  *         back into the stream via ungetc, it will be the first character 
  340.  *         returned. 
  341.  *
  342.  *         It is not possible for both bytes to be read and an APR_EOF or other 
  343.  *         error to be returned.
  344.  *
  345.  *         APR_EINTR is never returned.
  346.  */
  347. APR_DECLARE(apr_status_t) apr_file_read(apr_file_t *thefile, void *buf,
  348.                                    apr_size_t *nbytes);
  349.  
  350. /**
  351.  * Write data to the specified file.
  352.  * @param thefile The file descriptor to write to.
  353.  * @param buf The buffer which contains the data.
  354.  * @param nbytes On entry, the number of bytes to write; on exit, the number 
  355.  *               of bytes written.
  356.  * @remark apr_file_write will write up to the specified number of bytes, but never 
  357.  *      more.  If the OS cannot write that many bytes, it will write as many 
  358.  *      as it can.  The third argument is modified to reflect the * number 
  359.  *      of bytes written. 
  360.  *
  361.  *      It is possible for both bytes to be written and an error to be returned.
  362.  *
  363.  *      APR_EINTR is never returned.
  364.  */
  365. APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf,
  366.                                     apr_size_t *nbytes);
  367.  
  368. /**
  369.  * Write data from iovec array to the specified file.
  370.  * @param thefile The file descriptor to write to.
  371.  * @param vec The array from which to get the data to write to the file.
  372.  * @param nvec The number of elements in the struct iovec array. This must 
  373.  *             be smaller than APR_MAX_IOVEC_SIZE.  If it isn't, the function 
  374.  *             will fail with APR_EINVAL.
  375.  * @param nbytes The number of bytes written.
  376.  * @remark It is possible for both bytes to be written and an error to be returned.
  377.  *      APR_EINTR is never returned.
  378.  *
  379.  *      apr_file_writev is available even if the underlying operating system 
  380.  *
  381.  *      doesn't provide writev().
  382.  */
  383. APR_DECLARE(apr_status_t) apr_file_writev(apr_file_t *thefile,
  384.                                      const struct iovec *vec,
  385.                                      apr_size_t nvec, apr_size_t *nbytes);
  386.  
  387. /**
  388.  * Read data from the specified file, ensuring that the buffer is filled
  389.  * before returning.
  390.  * @param thefile The file descriptor to read from.
  391.  * @param buf The buffer to store the data to.
  392.  * @param nbytes The number of bytes to read.
  393.  * @param bytes_read If non-NULL, this will contain the number of bytes read.
  394.  * @remark apr_file_read will read up to the specified number of bytes, but never 
  395.  *      more.  If there isn't enough data to fill that number of bytes, 
  396.  *      then the process/thread will block until it is available or EOF 
  397.  *      is reached.  If a char was put back into the stream via ungetc, 
  398.  *      it will be the first character returned. 
  399.  *
  400.  *      It is possible for both bytes to be read and an error to be 
  401.  *      returned.  And if *bytes_read is less than nbytes, an
  402.  *      accompanying error is _always_ returned.
  403.  *
  404.  *      APR_EINTR is never returned.
  405.  */
  406. APR_DECLARE(apr_status_t) apr_file_read_full(apr_file_t *thefile, void *buf,
  407.                                         apr_size_t nbytes,
  408.                                         apr_size_t *bytes_read);
  409.  
  410. /**
  411.  * Write data to the specified file, ensuring that all of the data is
  412.  * written before returning.
  413.  * @param thefile The file descriptor to write to.
  414.  * @param buf The buffer which contains the data.
  415.  * @param nbytes The number of bytes to write.
  416.  * @param bytes_written If non-NULL, this will contain the number of bytes written.
  417.  * @remark apr_file_write will write up to the specified number of bytes, but never 
  418.  *      more.  If the OS cannot write that many bytes, the process/thread 
  419.  *      will block until they can be written. Exceptional error such as 
  420.  *      "out of space" or "pipe closed" will terminate with an error.
  421.  *
  422.  *      It is possible for both bytes to be written and an error to be 
  423.  *      returned.  And if *bytes_written is less than nbytes, an
  424.  *      accompanying error is _always_ returned.
  425.  *
  426.  *      APR_EINTR is never returned.
  427.  */
  428. APR_DECLARE(apr_status_t) apr_file_write_full(apr_file_t *thefile, const void *buf,
  429.                                          apr_size_t nbytes, 
  430.                                          apr_size_t *bytes_written);
  431.  
  432. /**
  433.  * put a character into the specified file.
  434.  * @param ch The character to write.
  435.  * @param thefile The file descriptor to write to
  436.  */
  437. APR_DECLARE(apr_status_t) apr_file_putc(char ch, apr_file_t *thefile);
  438.  
  439. /**
  440.  * get a character from the specified file.
  441.  * @param ch The character to read into
  442.  * @param thefile The file descriptor to read from
  443.  */
  444. APR_DECLARE(apr_status_t) apr_file_getc(char *ch, apr_file_t *thefile);
  445.  
  446. /**
  447.  * put a character back onto a specified stream.
  448.  * @param ch The character to write.
  449.  * @param thefile The file descriptor to write to
  450.  */
  451. APR_DECLARE(apr_status_t) apr_file_ungetc(char ch, apr_file_t *thefile);
  452.  
  453. /**
  454.  * Get a string from a specified file.
  455.  * @param str The buffer to store the string in. 
  456.  * @param len The length of the string
  457.  * @param thefile The file descriptor to read from
  458.  * @remark The buffer will be '\0'-terminated if any characters are stored.
  459.  */
  460. APR_DECLARE(apr_status_t) apr_file_gets(char *str, int len, apr_file_t *thefile);
  461.  
  462. /**
  463.  * Put the string into a specified file.
  464.  * @param str The string to write. 
  465.  * @param thefile The file descriptor to write to
  466.  */
  467. APR_DECLARE(apr_status_t) apr_file_puts(const char *str, apr_file_t *thefile);
  468.  
  469. /**
  470.  * Flush the file's buffer.
  471.  * @param thefile The file descriptor to flush
  472.  */
  473. APR_DECLARE(apr_status_t) apr_file_flush(apr_file_t *thefile);
  474.  
  475. /**
  476.  * duplicate the specified file descriptor.
  477.  * @param new_file The structure to duplicate into. 
  478.  * @param old_file The file to duplicate.
  479.  * @param p The pool to use for the new file.
  480.  * @remark *new_file must point to a valid apr_file_t, or point to NULL
  481.  */         
  482. APR_DECLARE(apr_status_t) apr_file_dup(apr_file_t **new_file,
  483.                                       apr_file_t *old_file,
  484.                                       apr_pool_t *p);
  485.  
  486. /**
  487.  * duplicate the specified file descriptor and close the original
  488.  * @param new_file The old file that is to be closed and reused
  489.  * @param old_file The file to duplicate
  490.  * @param p        The pool to use for the new file
  491.  *
  492.  * @remark new_file MUST point at a valid apr_file_t. It cannot be NULL
  493.  */
  494. APR_DECLARE(apr_status_t) apr_file_dup2(apr_file_t *new_file,
  495.                                         apr_file_t *old_file,
  496.                                         apr_pool_t *p);
  497.  
  498. /**
  499.  * move the specified file descriptor to a new pool
  500.  * @param new_file Pointer in which to return the new apr_file_t
  501.  * @param old_file The file to move
  502.  * @param p        The pool to which the descriptor is to be moved
  503.  * @remark Unlike apr_file_dup2(), this function doesn't do an
  504.  *         OS dup() operation on the underlying descriptor; it just
  505.  *         moves the descriptor's apr_file_t wrapper to a new pool.
  506.  * @remark The new pool need not be an ancestor of old_file's pool.
  507.  * @remark After calling this function, old_file may not be used
  508.  */
  509. APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file,
  510.                                             apr_file_t *old_file,
  511.                                             apr_pool_t *p);
  512.  
  513. /**
  514.  * Move the read/write file offset to a specified byte within a file.
  515.  * @param thefile The file descriptor
  516.  * @param where How to move the pointer, one of:
  517.  * <PRE>
  518.  *            APR_SET  --  set the offset to offset
  519.  *            APR_CUR  --  add the offset to the current position 
  520.  *            APR_END  --  add the offset to the current file size 
  521.  * </PRE>
  522.  * @param offset The offset to move the pointer to.
  523.  * @remark The third argument is modified to be the offset the pointer
  524.           was actually moved to.
  525.  */
  526. APR_DECLARE(apr_status_t) apr_file_seek(apr_file_t *thefile, 
  527.                                    apr_seek_where_t where,
  528.                                    apr_off_t *offset);
  529.  
  530. /**
  531.  * Create an anonymous pipe.
  532.  * @param in The file descriptor to use as input to the pipe.
  533.  * @param out The file descriptor to use as output from the pipe.
  534.  * @param cont The pool to operate on.
  535.  */
  536. APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out,
  537.                                           apr_pool_t *cont);
  538.  
  539. /**
  540.  * Create a named pipe.
  541.  * @param filename The filename of the named pipe
  542.  * @param perm The permissions for the newly created pipe.
  543.  * @param cont The pool to operate on.
  544.  */
  545. APR_DECLARE(apr_status_t) apr_file_namedpipe_create(const char *filename, 
  546.                                                apr_fileperms_t perm, 
  547.                                                apr_pool_t *cont);
  548.  
  549. /**
  550.  * Get the timeout value for a pipe or manipulate the blocking state.
  551.  * @param thepipe The pipe we are getting a timeout for.
  552.  * @param timeout The current timeout value in microseconds. 
  553.  */
  554. APR_DECLARE(apr_status_t) apr_file_pipe_timeout_get(apr_file_t *thepipe, 
  555.                                                apr_interval_time_t *timeout);
  556.  
  557. /**
  558.  * Set the timeout value for a pipe or manipulate the blocking state.
  559.  * @param thepipe The pipe we are setting a timeout on.
  560.  * @param timeout The timeout value in microseconds.  Values < 0 mean wait 
  561.  *        forever, 0 means do not wait at all.
  562.  */
  563. APR_DECLARE(apr_status_t) apr_file_pipe_timeout_set(apr_file_t *thepipe, 
  564.                                                apr_interval_time_t timeout);
  565.  
  566. /** file (un)locking functions. */
  567.  
  568. /**
  569.  * Establish a lock on the specified, open file. The lock may be advisory
  570.  * or mandatory, at the discretion of the platform. The lock applies to
  571.  * the file as a whole, rather than a specific range. Locks are established
  572.  * on a per-thread/process basis; a second lock by the same thread will not
  573.  * block.
  574.  * @param thefile The file to lock.
  575.  * @param type The type of lock to establish on the file.
  576.  */
  577. APR_DECLARE(apr_status_t) apr_file_lock(apr_file_t *thefile, int type);
  578.  
  579. /**
  580.  * Remove any outstanding locks on the file.
  581.  * @param thefile The file to unlock.
  582.  */
  583. APR_DECLARE(apr_status_t) apr_file_unlock(apr_file_t *thefile);
  584.  
  585. /**accessor and general file_io functions. */
  586.  
  587. /**
  588.  * return the file name of the current file.
  589.  * @param new_path The path of the file.  
  590.  * @param thefile The currently open file.
  591.  */                     
  592. APR_DECLARE(apr_status_t) apr_file_name_get(const char **new_path, 
  593.                                            apr_file_t *thefile);
  594.  
  595. /**
  596.  * Return the data associated with the current file.
  597.  * @param data The user data associated with the file.  
  598.  * @param key The key to use for retreiving data associated with this file.
  599.  * @param file The currently open file.
  600.  */                     
  601. APR_DECLARE(apr_status_t) apr_file_data_get(void **data, const char *key, 
  602.                                            apr_file_t *file);
  603.  
  604. /**
  605.  * Set the data associated with the current file.
  606.  * @param file The currently open file.
  607.  * @param data The user data to associate with the file.  
  608.  * @param key The key to use for assocaiteing data with the file.
  609.  * @param cleanup The cleanup routine to use when the file is destroyed.
  610.  */                     
  611. APR_DECLARE(apr_status_t) apr_file_data_set(apr_file_t *file, void *data,
  612.                                            const char *key,
  613.                                            apr_status_t (*cleanup)(void *));
  614.  
  615. /**
  616.  * Write a string to a file using a printf format.
  617.  * @param fptr The file to write to.
  618.  * @param format The format string
  619.  * @param ... The values to substitute in the format string
  620.  * @return The number of bytes written
  621.  */ 
  622. APR_DECLARE_NONSTD(int) apr_file_printf(apr_file_t *fptr, 
  623.                                         const char *format, ...)
  624.         __attribute__((format(printf,2,3)));
  625.  
  626. /**
  627.  * set the specified file's permission bits.
  628.  * @param fname The file (name) to apply the permissions to.
  629.  * @param perms The permission bits to apply to the file.
  630.  * @warning Some platforms may not be able to apply all of the available 
  631.  *      permission bits; APR_INCOMPLETE will be returned if some permissions 
  632.  *      are specified which could not be set.
  633.  *
  634.  *      Platforms which do not implement this feature will return APR_ENOTIMPL.
  635.  */
  636. APR_DECLARE(apr_status_t) apr_file_perms_set(const char *fname,
  637.                                            apr_fileperms_t perms);
  638.  
  639. /**
  640.  * Set attributes of the specified file.
  641.  * @param fname The full path to the file (using / on all systems)
  642.  * @param attributes Or'd combination of
  643.  * <PRE>
  644.  *            APR_FILE_ATTR_READONLY   - make the file readonly
  645.  *            APR_FILE_ATTR_EXECUTABLE - make the file executable
  646.  *            APR_FILE_ATTR_HIDDEN     - make the file hidden
  647.  * </PRE>
  648.  * @param attr_mask Mask of valid bits in attributes.
  649.  * @param cont the pool to use.
  650.  * @remark This function should be used in preference to explict manipulation
  651.  *      of the file permissions, because the operations to provide these
  652.  *      attributes are platform specific and may involve more than simply
  653.  *      setting permission bits.
  654.  * @warning Platforms which do not implement this feature will return
  655.  *      APR_ENOTIMPL.
  656.  */
  657. APR_DECLARE(apr_status_t) apr_file_attrs_set(const char *fname,
  658.                                              apr_fileattrs_t attributes,
  659.                                              apr_fileattrs_t attr_mask,
  660.                                              apr_pool_t *cont);
  661.  
  662. /**
  663.  * Set the mtime of the specified file.
  664.  * @param fname The full path to the file (using / on all systems)
  665.  * @param mtime The mtime to apply to the file.
  666.  * @param pool The pool to use.
  667.  * @warning Platforms which do not implement this feature will return
  668.  *      APR_ENOTIMPL.
  669.  */
  670. APR_DECLARE(apr_status_t) apr_file_mtime_set(const char *fname,
  671.                                              apr_time_t mtime,
  672.                                              apr_pool_t *pool);
  673.  
  674. /**
  675.  * Create a new directory on the file system.
  676.  * @param path the path for the directory to be created.  (use / on all systems)
  677.  * @param perm Permissions for the new direcoty.
  678.  * @param cont the pool to use.
  679.  */                        
  680. APR_DECLARE(apr_status_t) apr_dir_make(const char *path, apr_fileperms_t perm, 
  681.                         apr_pool_t *cont);
  682.  
  683. /** Creates a new directory on the file system, but behaves like
  684.  * 'mkdir -p'. Creates intermediate directories as required. No error
  685.  * will be reported if PATH already exists.
  686.  * @param path the path for the directory to be created.  (use / on all systems)
  687.  * @param perm Permissions for the new direcoty.
  688.  * @param pool the pool to use.
  689.  */
  690. APR_DECLARE(apr_status_t) apr_dir_make_recursive(const char *path,
  691.                                                  apr_fileperms_t perm,
  692.                                                  apr_pool_t *pool);
  693.  
  694. /**
  695.  * Remove directory from the file system.
  696.  * @param path the path for the directory to be removed.  (use / on all systems)
  697.  * @param cont the pool to use.
  698.  */                        
  699. APR_DECLARE(apr_status_t) apr_dir_remove(const char *path, apr_pool_t *cont);
  700.  
  701. /**
  702.  * get the specified file's stats.
  703.  * @param finfo Where to store the information about the file.
  704.  * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values 
  705.  * @param thefile The file to get information about.
  706.  */ 
  707. APR_DECLARE(apr_status_t) apr_file_info_get(apr_finfo_t *finfo, 
  708.                                           apr_int32_t wanted,
  709.                                           apr_file_t *thefile);
  710.  
  711.  
  712. /**
  713.  * Truncate the file's length to the specified offset
  714.  * @param fp The file to truncate
  715.  * @param offset The offset to truncate to.
  716.  */
  717. APR_DECLARE(apr_status_t) apr_file_trunc(apr_file_t *fp, apr_off_t offset);
  718.  
  719. /**
  720.  * Retrieve the flags that were passed into apr_file_open()
  721.  * when the file was opened.
  722.  * @return apr_int32_t the flags
  723.  */
  724. APR_DECLARE(apr_int32_t) apr_file_flags_get(apr_file_t *f);
  725.  
  726. /**
  727.  * Get the pool used by the file.
  728.  */
  729. APR_POOL_DECLARE_ACCESSOR(file);
  730.  
  731. /**
  732.  * Set a file to be inherited by child processes.
  733.  *
  734.  */
  735. APR_DECLARE_INHERIT_SET(file);
  736.  
  737. /** @deprecated @see apr_file_inherit_set */
  738. APR_DECLARE(void) apr_file_set_inherit(apr_file_t *file);
  739.  
  740. /**
  741.  * Unset a file from being inherited by child processes.
  742.  */
  743. APR_DECLARE_INHERIT_UNSET(file);
  744.  
  745. /** @deprecated @see apr_file_inherit_unset */
  746. APR_DECLARE(void) apr_file_unset_inherit(apr_file_t *file);
  747.  
  748. /**
  749.  * Open a temporary file
  750.  * @param fp The apr file to use as a temporary file.
  751.  * @param templ The template to use when creating a temp file.
  752.  * @param flags The flags to open the file with. If this is zero,
  753.  *              the file is opened with 
  754.  *              APR_CREATE | APR_READ | APR_WRITE | APR_EXCL | APR_DELONCLOSE
  755.  * @param p The pool to allocate the file out of.
  756.  * @remark   
  757.  * This function  generates  a unique temporary file name from template.  
  758.  * The last six characters of template must be XXXXXX and these are replaced 
  759.  * with a string that makes the filename unique. Since it will  be  modified,
  760.  * template must not be a string constant, but should be declared as a character
  761.  * array.  
  762.  *
  763.  */
  764. APR_DECLARE(apr_status_t) apr_file_mktemp(apr_file_t **fp, char *templ,
  765.                                           apr_int32_t flags, apr_pool_t *p);
  766.  
  767.  
  768. /**
  769.  * Find an existing directory suitable as a temporary storage location.
  770.  * @param temp_dir The temp directory.
  771.  * @param p The pool to use for any necessary allocations.
  772.  * @remark   
  773.  * This function uses an algorithm to search for a directory that an
  774.  * an application can use for temporary storage.  Once such a
  775.  * directory is found, that location is cached by the library.  Thus,
  776.  * callers only pay the cost of this algorithm once if that one time
  777.  * is successful.
  778.  *
  779.  */
  780. APR_DECLARE(apr_status_t) apr_temp_dir_get(const char **temp_dir, 
  781.                                            apr_pool_t *p);
  782.  
  783. /** @} */
  784.  
  785. #ifdef __cplusplus
  786. }
  787. #endif
  788.  
  789. #endif  /* ! APR_FILE_IO_H */
  790.